use serde::{Deserialize, Serialize};
use ts_rs::TS;

use super::IndicatorActionWrap;

/// Struct to hold the results of multi-period Relative Strength Index (RSI) calculations.
///
/// 参见[RSI](https://docs.rs/yata/latest/yata/indicators/type.RSI.html)
///
/// yata::indicators::RelativeStrengthIndex
///
#[derive(Serialize, Deserialize, Default, Debug, TS, Clone)]
#[ts(export)]
pub struct RSI {
    /// Signal #1 on enters over-zone.
    /// When main value crosses upper zone upwards, returns full sell signal.
    /// When main value crosses lower zone downwards, returns full buy signal.
    /// Otherwise returns no signal.
    pub signal0: Option<IndicatorActionWrap>,
    /// Signal #2 on leaves over-zone.
    /// When main value crosses upper zone downwards, returns full sell signal.
    /// When main value crosses lower zone upwards, returns full buy signal.
    /// Otherwise returns no signal.
    pub signal1: Option<IndicatorActionWrap>,

    /// upper zone
    pub upper: f64,
    /// main value
    /// Range in [0.0; 1.0]
    pub main: f64,

    /// lower zone
    pub lower: f64,
}

/// Configuration Relative Strength Index (RSI) indicator
#[derive(Serialize, Deserialize, Debug, TS, Clone, Copy)]
#[ts(export)]
pub struct RSIConfig {
    /// Main MA type.
    ///
    /// Default is EMA(14)
    /// Period range in [3; PeriodType::MAX).
    pub ma: u8,

    /// Overbought/oversell relative zone.
    ///
    /// Default is 0.3.
    /// Range in (0.0; 0.5]
    pub zone: f64,
    // source: Source
    // Source type of values. Default is Close
}

impl Default for RSIConfig {
    fn default() -> Self {
        Self { ma: 14, zone: 0.3 }
    }
}
